<template>
  <van-form @submit="onSubmit">
    <van-row justify="center">
      <van-image
          width="343"
          :src= campusImage
          style="background-position:center"
      />
    </van-row>
    <van-cell-group inset>
      <van-field
          v-model="phone"
          name="phone"
          label="手机号"
          placeholder="请输入绑定的手机号"
          :rules="[{ required: true, message: '请输入绑定的手机号' }]"
      />
        <van-field
            v-model="userPassword"
            name="userPassword"
            label="密码"
            placeholder="请输入更改的密码"
            :rules="[{ required: true, message: '请输入更改的密码' }]"
        />
      <van-field
          v-model="confirmPassword"
          name="confirmPassword"
          label="确认密码"
          placeholder="请重新输入更改的密码"
          :rules="[{ required: true, message: '请重新输入更改的密码' }]"
      />
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        提交
      </van-button>
    </div>
  </van-form>

</template>

<script setup lang="ts">
import {ref} from 'vue';

import {useRoute, useRouter} from "vue-router";
import {Toast} from "@vant/compat";
import myAxios from "../plugins/myAxios";
import campusImage from "../assets/patient.png"

const route=useRoute();
const router=useRouter();
const phone=ref('');
const userPassword=ref('');
const confirmPassword = ref('');
const onSubmit = async () => {
  // console.log("用户登录");
  const res = await myAxios.post("/user/forget", {
    phone: phone.value,
    userPassword: userPassword.value,
    confirmPassword: confirmPassword.value
  });
  if (res.code == 0 && res.data != null) {
    Toast.success("修改成功");
    await router.replace("/user")
  } else {
    console.log('/user/forget error');
    Toast.fail("修改失败");
  }
};

</script>

<style scoped>

</style>